package ai.people.platform.jx.controller;


import ai.people.netmon.framework.domain.common.SimpleNameValueRespVO;
import ai.people.netmon.framework.domain.jx.AfricaTerrorismEvent;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.framework.model.response.Result;
import ai.people.platform.jx.service.IAfricaTerrorismService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 非洲恐怖袭击事件相关接口
 *
 * @author LiGuanNan
 * @date 2022/5/31 下午2:23
 */
@Slf4j
@RestController
@RequestMapping("v1/africa")
public class AfricaTerrorismController {

    @Autowired
    private IAfricaTerrorismService africaTerrorismService;


    /**
     * 非洲恐怖主义事件数据源网站表格预览
     */
    @GetMapping(value = "web-excel")
    public Result<List<Map<String, Object>>> webExcel() {
        return new Result<>(africaTerrorismService.webExcel());
    }


    /**
     * 非洲恐怖主义事件表格预览
     */
    @GetMapping(value = "event-excel")
    public Result<PageResponse<AfricaTerrorismEvent>> eventExcel(@RequestParam Integer pageNo,
                                                                 @RequestParam Integer pageSize,
                                                                 @RequestParam(required = false) Integer beginYear,
                                                                 @RequestParam(required = false) Integer endYear) {
        return new Result<>(africaTerrorismService.eventExcel(pageNo, pageSize, beginYear, endYear));
    }

    /**
     * 非洲恐怖主义事件概述&预测
     */
    @GetMapping(value = "over-view")
    public Result<JSONObject> overView() {
        return new Result<>(africaTerrorismService.overView());
    }

    /**
     * 非洲恐怖主义事件分页
     */
    @GetMapping(value = "events")
    public Result<PageResponse<AfricaTerrorismEvent>> events(@RequestParam Integer pageNo,
                                                             @RequestParam Integer pageSize,
                                                             @RequestParam String country,
                                                             @RequestParam(required = false) Integer beginYear,
                                                             @RequestParam(required = false) Integer endYear) {
        return new Result<>(africaTerrorismService.queryEventPage(pageNo, pageSize, country, beginYear, endYear));
    }

    /**
     * 非洲恐怖主义事件统计分析
     */
    @GetMapping(value = "statistics")
    public Result<List<SimpleNameValueRespVO>> statistics(@RequestParam String country) {
        return new Result<>(africaTerrorismService.statistics(country));
    }

    /**
     * 非洲恐怖主义事件预警
     */
    @GetMapping(value = "warn")
    public Result<Integer> warn(@RequestParam Integer year,
                                @RequestParam String country) {
        return new Result<>(africaTerrorismService.calWarning(year, country));
    }


}
